#include "dialogimpl.h"
#include <QDateTime>
#include <QtConcurrentRun>
#include <QFuture>
//
//const int n = 80000;
const int n = 6000;

void proces( QVector< QVector<double> > * msrc,QVector<double> & mres, int i/*, int j*/){
	double res;
	for(int j = 0; j < n; ++j){
		res = 0;
		for(int k = 0; k < n; ++k){
			res += msrc->at(i).at(k) * msrc->at(k).at(j);
		}
		mres[j] = res;
	}
}

void setLine(QVector<double> & line){
	for(int i = 0, l = line.size(); i < l; ++i){
		line[i] = rand();
	}
}

DialogImpl::DialogImpl( QWidget * parent, Qt::WFlags f) 
	: QDialog(parent, f){
	setupUi(this);
	QString str;
	QDateTime tstart, tstop;

	QVector< QVector<double> > msrc(n, QVector<double>(n));
	QVector< QVector<double> > mres(n, QVector<double>(n));
////Заполню матрицу.//////////////////////////////////////////////////////////////////
	str = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz");
	lbl_1->setText(str);
	qDebug()<<str;
	for(int i = 0; i < n; ++i)
		QtConcurrent::run(setLine, msrc[i]);
	str = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz");
	lbl_2->setText(str);
	qDebug()<<str;

////Перемножу./////////////////////////////////////////////////////////////////////////
	tstart = QDateTime::currentDateTime();
	str = tstart.toString("dd.MM.yyyy hh:mm:ss.zzz");
	lbl_3->setText(str);
	qDebug()<<str;
	QList<QFuture<void>*> futures;
	for(int i = 0; i < n; ++i)
		futures.append(new QFuture<void>(QtConcurrent::run(proces, &msrc, mres[i], i)));
	for(int i = 0, l = futures.size(); i < l; ++i)
		futures.at(i)->waitForFinished();
	tstop = QDateTime::currentDateTime();
	str = tstop.toString("dd.MM.yyyy hh:mm:ss.zzz");
	lbl_4->setText(str);
	qDebug()<<str;
	str =  QString::number(tstart.msecsTo(tstop));
	qDebug()<<str;
	for(int i = 0, l = futures.size(); i < l; ++i)
		delete futures[i];
}
//
